﻿@using eLoan.Models;
@model AgentListModel

@{
    ViewBag.Title = "Agents";
}

<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>Agents</h2>
        <ol class="breadcrumb">
            <li>
                Administration
            </li>
            <li class="active">
                <strong>Agents</strong>
            </li>
        </ol>
    </div>
    <div class="col-lg-2"></div>
</div>

@using (Html.BeginForm("RefreshAgents", "Administration", new { branchCode = Model.SelectedBranchCode }, FormMethod.Post))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <a href="@Url.Action("AddEdit", "Agent", new { branchCode = Model.SelectedBranchCode})" class="btn btn-primary">Add a new agent</a>
                </div>
                <div class="ibox-title">
                    @Html.LabelFor(m => Model.SelectedBranchCode)
                    @Html.DropDownListFor(m => Model.SelectedBranchCode, Model.Branches, new { @class = "single-line", @onchange="Refresh();", @style="width:25%" })
                </div>
                <div class="ibox-content">
                    <div class="scrollable">
                        <table class="table table-bordered">
                            <thead class="k-grid-header">
                                <tr>
                                    <th>Name</th>
                                    <th>Address</th>
                                    <th>Contact Numbers</th>
                                    <th>Guarantor</th>
                                    <th>Guarantor Contact Numbers</th>
                                    <th>Is Active</th>
                                    <th></th>
                                </tr>
                            </thead>
                            <tbody>
                                @for (var i = 0; i < Model.Agents.Count(); i ++ )
                                { 
                                <tr>
                                    <td>@Html.DisplayFor(m => Model.Agents[i].Agent.AgentName)</td>
                                    <td>@Html.DisplayFor(m => Model.Agents[i].Agent.Address)</td>
                                    <td>@Html.DisplayFor(m => Model.Agents[i].Agent.ContactNumbers)</td>
                                    <td>@Html.DisplayFor(m => Model.Agents[i].Agent.Guarantor)</td>
                                    <td>@Html.DisplayFor(m => Model.Agents[i].Agent.GuarantorContactNumbers)</td>
                                    <td style="text-align:center">@Html.DisplayFor(m => Model.Agents[i].Agent.IsActive)</td>
                                    <td>@Html.ActionLink("Edit", "AddEdit", "Agent", null, null, null, new { id = Model.Agents[i].Agent.ID }, null)</td>
                                </tr>
                                }
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>
    
<button type="submit" id="btnRefresh" style="display:none" name="command" value="Refresh"></button>
    
}

@section Styles {
    @Styles.Render("~/Content/plugins/dataTables/dataTablesStyles")

<style>
    .scrollable {
        height: 400px;
        overflow-y: scroll;
        border: solid 1px #EBEBEB;
    }
</style>

}

@section Scripts {

    <script type="text/javascript">

        function Refresh() {
            document.getElementById('btnRefresh').click();
        }

    </script>

}